import {
  getTotalChannelConversion,
  getChannelConversion,
} from '../../services/channel/api';


export default {
  namespace: 'channelConversion',

  state: {

    loading: true,

    channelConverData:{
      list:[],
      pagination: {},
    },
  },

  effects: {
    *fetchGetChannelConversion({ payload }, { call, put }) {
      const response = yield call(getChannelConversion, payload);
      if (response && response.code == 200) {
        yield put({
          type: 'save',
          payload: {
            channelConverData: {
              list: response.data.records,
              pagination:{
                current: response.data.current,
                total: response.data.total,
              }
            }
          },
        });
      }
    },
    *fetchGetTotalChannelConversion({ payload }, { call, put }) {
      const response = yield call(getTotalChannelConversion, payload);
      if (response && response.code == 200) {
        yield put({
          type: 'save',
          payload: {
            getTotalData:response.data
          },
        });
      }
    },
  },

  reducers: {
    save(state, { payload }) {
      return {
        ...state,
        ...payload,
      };
    },
  },

};
